<!-- 作业: 对一个数组(数字型)进行升序排序,并将这个功能封装为一个函数,使其更具有普适性.
例如: 原数组 [3,6,81,4,0,7] 将其排序之后变成升序排列:[0,3,4,6,7,81] -->
<!-- 在尝试数组读取自由，如果这段话没删就是没成功，sad -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Ascending-Order</title>
    
</head>
<body>
    <script type="text/javascript">
        var arr1 = [3,6,81,4,0,7];
        /* function inputData(){
            var arr1 = document.getElementById("arr2").value;
            string +=arr1;
            alert(string);
        } */
        /* 定义数组 */
        function Sorting(){   
            var len = arr1.length;
            for(var i = 0; i < len- 1;i++){
                for(var j = 0;j<len-1-i;j++){
                    if(arr1[j]>arr1[j+1]){
                        var temp = arr1[j+1];
                        arr1[j+1]=arr1[j];
                        arr1[j]=temp;
                    }
                }
            }
            /* 对数组进行冒泡排序法 */
            for(var i=0;i<arr1.length;i++){
            document.writeln(arr1[i]);
        }
        /* 输出排序好的数组 */
        }
    </script>
    <!-- <form>
        请输入数组
        <br>
        <input type="text" name="arr2">
        <br>
        <button type="submit" onclick="inputData()">submit</button>
    </form> -->
    <script>
        Sorting();
    </script>
</body>
</html>